Compositing Operators



Methods for combining and mixing images.

Input images


Given the input images $A$ and $B$ (sRGB colorspace).

p.s.: All the input images are normalized between 0-1.

Alpha compositing operators


Over


$$ \large O = A\alpha+B(1-\alpha) $$

Atop


$$ \large O = A\beta+B(1-\alpha) $$

Conjoint over


$$ \large O = \begin{cases} A &, \text{if } \alpha > \beta \\ A+\frac{B(1-\alpha)}{\beta} &, \text{otherwise} \end{cases} $$

Disjoint over


$$ \large O = \begin{cases} A+B &, \text{if } \alpha+\beta < 1 \\ A+\frac{B(1-\alpha)}{\beta} &, \text{otherwise} \end{cases} $$

In


$$ \large O = A\beta $$

Xor


$$ \large O = A(1 - \beta) + B(1 - \alpha) $$

Blend modes


Due the input images are in sRGB colorspace, it is necessary to linearize them by the $\gamma = 2.2$ before operating and the output must be transformed to sRGB by inverting the $\gamma$.

$$ \large I' = I^{\gamma} \quad ; \quad O' = O^{\frac{1}{\gamma}} $$

Average


$$ \large O' = \frac{A'+B'}{2} $$

Color burn


$$ \large O' = 1 - \frac{1-B'}{A'} $$

Difference


$$ \large O' = |A'-B'| $$

Division


$$ \large O' = \frac{A'}{B'} $$

Exclusion


$$ \large O' = A'+B'-2A'B' $$

From


$$ \large O' = B'- A' $$

Geometric


$$ \large O' = \frac{2A'B'}{A'+B'} $$

Hypot


$$ \large O' = \sqrt{A'^2+B'^2} $$

Max


$$ \large O' = \max(A', B') $$

Min


$$ \large O' = \min(A', B') $$

Minus


$$ \large O' = A'- B' $$

Multiply


$$ \large O' = A'B' $$

Plus


$$ \large O' = A' + B' $$

Screen


$$ \large O' = A' + B' - A'B' $$

Soft light


$$ \large O' = B'(2A' + B'(1 - A'B')) $$

Hard light


$$ \large O' = \begin{cases} \text{multiply}&, \text{if } A < \frac{1}{2} \\ \text{screen}&, \text{otherwise} \end{cases} $$

Overlay


$$ \large O' = \begin{cases} \text{multiply}&, \text{if } B < \frac{1}{2} \\ \text{screen}&, \text{otherwise} \end{cases} $$